package com.easyCode.sqlMapper.mapInfoAdaptor;

import com.easyCode.mysql.sqlBuilder.sqlInfo.MysqlFiledSqlInfo;
import com.easyCode.sqlBuilder.SqlInfo;
import com.easyCode.sqlManager.MappingContainer;
import com.easyCode.sqlBuilder.sqlInfo.BaseFiledSqlInfo;
import com.easyCode.sqlMapper.mapInfo.FiledMapInfo;
import com.easyCode.util.StringUtil;

/**
 * @author 大忽悠
 * @create 2022/12/2 14:32
 */
public class FiledMapInfoAdaptor implements MapInfoAdaptor<FiledMapInfo> {
    /**
     * @param source sqlInfo子类
     * @return 当前适配器是否支持适配当前sqlInfo
     */
    @Override
    public boolean support(SqlInfo source) {
        return source instanceof BaseFiledSqlInfo;
    }

    /**
     * @param source sqlInfo子类
     * @return mapInfo子类
     */
    @Override
    public FiledMapInfo adapter(SqlInfo source) {
        MysqlFiledSqlInfo mysqlFiledSqlInfo = (MysqlFiledSqlInfo) source;
        FiledMapInfo filedMapInfo = FiledMapInfo.builder().
                filedName(StringUtil.underlineToCamel(mysqlFiledSqlInfo.getFiledName()))
                .comment(mysqlFiledSqlInfo.getComment())
                .order(mysqlFiledSqlInfo.getOrder()).build();
        filedMapInfo.setMapType(MappingContainer.getJavaType(mysqlFiledSqlInfo.getFiledType()).getSimpleName());
        return filedMapInfo;
    }
}
